﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.achievements.data {
    import Engine.Managers.*;
    import Modules.stats.types.*;

    public class AchievementGroup {

        public var id:String;
        public var start:Number;
        public var end:Number;
        public var expire:Number;
        public var achievements:Array;
        public var dt:int = 0;

        public function AchievementGroup(_arg1:XML){
            var _local2:XML;
            var _local3:Achievement;
            super();
            this.id = String(_arg1.@id);
            this.start = Date.parse(String(_arg1.@start));
            this.end = Date.parse(String(_arg1.@end));
            this.expire = Date.parse(String(_arg1.@expire));
            this.achievements = [];
            for each (_local2 in _arg1.achievements.achievement) {
                _local3 = new Achievement(_local2, this.id);
                this.achievements.push(_local3);
            };
        }
        public function update(_arg1:Object, _arg2:Object):void{
            var _local3:String;
            var _local4:Object;
            var _local5:Achievement;
            this.dt = int(_arg1["dt"]);
            for (_local3 in _arg1.achievements) {
                _local4 = _arg1.achievements[_local3];
                _local5 = this.getAchievement(_local3);
                if (_local5 != null){
                    _local5.update(_local4);
                    _local5.justUpdated = false;
                };
            };
            for each (_local3 in _arg2) {
                _local5 = this.getAchievement(_local3);
                if (_local5 != null){
                    _local5.justUpdated = true;
                    StatsManager.count(StatsCounterType.ACHIEVEMENTS, StatsKingdomType.ACH_NEW_STATE, this.id, _local5.id, _local5.state);
                };
            };
        }
        public function getAchievement(_arg1:String):Achievement{
            var _local2:Achievement;
            for each (_local2 in this.achievements) {
                if (_local2.id == _arg1){
                    return (_local2);
                };
            };
            return (null);
        }

    }
}//package Modules.achievements.data 
